<?php
$parentCaption = BUtils::T('offers_lbl');
$caption = BUtils::T('offers_list_lbl');
$this->pageTitle = $caption;

$this->breadcrumbs = array(
	$parentCaption => array('index'),
	$caption,
);

$list_template_btn = BUtils::T('template_list_view_lbl');
$all_lbl = BUtils::T('all_op_lbl');

//get url_offer_img
$url_offer_img = BUtils::GetOfferPictureUrl(str_replace('thumb_', '', $model[0]['url_offer_img']));
?>
<div class="page-header position-relative">
	<h1>
		<?php echo $parentCaption; ?>
		<small>
			<i class="icon-double-angle-right"></i>
			<?php echo $caption; ?>
		</small>
	</h1>
</div><!--/.page-header-->

<div class="row-fluid">
	<!-- Message -->
	<div class="alert alert-block alert-success">
		<button type="button" class="close" data-dismiss="alert">
			<i class="icon-remove"></i>
		</button>
		<i class="icon-info-sign green"></i>
		<?php echo BUtils::T('special_offer_list_eg'); ?>
	</div>
	
	<div class="space-6"></div>
	
	<div class="row-fluid">
		<div class="span9">
			<div class="widget-box transparent">
				<div class="widget-header">
					<h3 class="lighter blue"><?php echo $caption; ?></h3>
					<div class="widget-toolbar">
						<a href="<?php echo Yii::app()->createUrl('/offer/form'); ?>">
							<i class="icon-edit blue"></i>
							<span><?php echo BUtils::T('create_offer_lbl'); ?></span>
						</a>
					</div>
				</div>
				<div class="widget-body">
					<div class="widget-body-inner">
					<div class="widget-main no-padding">
						<div class="dataTables_wrapper">
<div class="row-fluid no-border">
	<div class="span12">
		<div class="dataTables_paginate" style="padding-right:8px;">
<?php
echo CHtml::form(Yii::app()->createUrl($this->id.'/'.$this->action->id), 'post', array('id'=>'search_form', 'style'=>'margin-bottom:8px;'));
//echo CHtml::dropDownList('filter_week', '', BUtils::WeekDayKeys(7), array('empty'=>$all_lbl, 'style'=>'width:auto;'));
echo CHtml::dropDownList('filter_status', '', BUtils::SpecialStatus(), array('empty'=>$all_lbl, 'style'=>'width:auto;'));
echo CHtml::dropDownList('filter_date', '', BUtils::SpecialValidStatus(), array('empty'=>$all_lbl, 'style'=>'width:auto;'));
echo CHtml::ajaxSubmitButton(BUtils::T('search_btn'), null, array('beforeSend'=>'beforeSend', 'success'=>'success'), array('class'=>'btn btn-blue'));
echo CHtml::endForm();
?>
		</div>
	</div>
</div>
						</div>	

<div class="mobile">
	<div id="loading-bar" style="text-align:center; margin:20px 0;">
		<img src="<?php echo Yii::app()->baseUrl; ?>/img/ajax-loaders/ajax-loader-4.gif" />
	</div>
	<div id="special-list"></div>
</div>
						
					</div>
					</div>
				</div>
			</div><!-- end of widget-box -->
			
		</div>
		
		<div class="span3">
			<div class="widget-box transparent">
				<div class="widget-header">
					<h5 class="lighter blue"><?php echo BUtils::T('default_offer_pciture_lbl'); ?></h5>
				</div>
				<div class="widget-body">
					<div class="widget-body-inner">
					<div class="widget-main">
<div class="row-fluid">
	<img id="img_offer" src="<?php echo $url_offer_img; ?>" class="img-polaroid span12" />
</div>
<div class="space-6"></div>
<div class="row-fluid">
<?php $this->widget('ext.EAjaxUpload.EAjaxUpload', array(
	'id' => 'uploadOfferImage',
	'config' => array(
		'buttonName' => BUtils::T('upload_new_picture_eg'),
		'action' => Yii::app()->createUrl('/merchant/uploadOfferImage'),
		'allowedExtensions'=>array("jpg","jpeg","gif","png"),
		'sizeLimit'=>8*1024*1024,
		'onComplete' => "js:function(id, fileName, responseJSON){ handleUploadedOffer(responseJSON); }",
	),
)); ?>
</div>
<div class="tips"><?php echo BUtils::T('default_offer_pciture_eg'); ?></div>
					</div>
					</div>
				</div>
			</div>
		</div>
		
	</div>
</div>
<script type="text/javascript">
$(function() {
	$.ajax({
		'beforeSend':beforeSend, 'success':success,
		'type':'POST', 'url':location.href, 'data':$('#search_form').serialize()
	});
	
	$('.special_counts a.label').click(function(){
		$('#search_form option').removeAttr('selected');
		var i = $(this).data('index');//find option index
		$('#filter_date option').eq(i).attr('selected', 'selected').trigger('change');
	});
	$('#search_form select').change(function(){
		$.ajax({
			'beforeSend':beforeSend, 'success':success,
			'type':'POST', 'url':location.href, 'data':$('#search_form').serialize()
		});
	});
});
function beforeSend() {
	$("#loading-bar").show();
	$("#special-list").html('');
}
function success(html) {
	$("#loading-bar").hide();
	$("#special-list").html(html);
}

function handleUploadedOffer(respJSON) {
	if (respJSON.error) {
		$('.qq-upload-button').html('<span>'+respJSON.error+'</span>');
	} else {
		if (respJSON.url_offer_img) {
			$('#img_offer').attr('src', respJSON.url_offer_img);
			$('ul.qq-upload-list').delay(1000).html('');
		}
	}
}
</script>